<?php
class Location_Detail extends CI_Model{
	public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	/**
	 * Kiem tra 1 dia diem da co trong location detail chua 
	 * Neu co tra ve true
	 * Neu khong co tra ve false
	 * Enter description here ...
	 * @param unknown_type $location_id
	 */
	public function checkExist($location_id){
		$this->db->where('location_id',$location_id);
		if($this->db->count_all_results('location_detail') > 0){
			return TRUE;
		}else{
			return FALSE;
		}
		
	}
	
	/**
	 * Lay 1 dia diem trong bang location ra dua vao location id
	 * Enter description here ...
	 * @param unknown_type $location_id
	 */
	public function getLocation($location_id){
		$query = $this->db->get_where('location_detail',array('location_id'=>$location_id));
		if($query->num_rows() > 0){
			return $query->first_row();
		}else{
			return null;
		}
	}
	
	/**
	 * Them moi 1 dia diem vao location detail
	 * Neu co location da ton tai thi khong lam gi
	 * Neu khong co thi them no vao location detail
	 * Enter description here ...
	 * @param array $param
	 * Chua cac thong tin ve 1 location
	 */
	public function insertLocation($param){
		if($this->checkExist($param["location_id"])){
			return FALSE;
		}else{
			$this->db->insert('location_detail',$param);
			return TRUE;
		}
	}
	
	/**
	 * Update 1 dia diem da ton tai trong DB
	 * Enter description here ...
	 * @param array $param 
	 * Chua cac thong tin ve 1 location
	 */
	public function updateLocation($param){
		if($this->checkExist($param['location_id'])){
			$this->db->where('location_id',$param["location_id"]);
			$this->db->update('location_detail',$param);
			return TRUE;
		}else{
			return false;
		}
		
	}
	
}